package ch0001;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class MyFrame3_2 extends JFrame {

	JLabel label_name;
	JTextField text_name;
	JLabel labelpassword;
	JPasswordField password1;
	JButton button1;
//	JButton button2;
	JRadioButton rb1, rb2, rb3;
	ButtonGroup group1;

	public MyFrame3_2() {
		setTitle("作业1");
		setSize(500, 300);
		rb1 = new JRadioButton("教师");
		rb2 = new JRadioButton("学生");
		rb3 = new JRadioButton("管理员");
		group1 = new ButtonGroup();
		group1.add(rb1);
		group1.add(rb2);
		group1.add(rb3);
		label_name = new JLabel("姓名");
		text_name = new JTextField(10);
		labelpassword = new JLabel("密码");
		password1 = new JPasswordField(10);
		button1 = new JButton("确定");
		button1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("you press button!");
				if (text_name.getText().trim().equals("abc") && password1.getText().trim().equals("123")
						&& rb1.isSelected()) {
					System.out.println("login now!");
					MyFrame2 myf2 = new MyFrame2();
					myf2.show();
					myf2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				}

			}
		});
//		button2 = new JButton("取消");

		Container c1 = getContentPane();
		c1.setLayout(new FlowLayout());
		c1.add(label_name);
		c1.add(text_name);
		c1.add(labelpassword);
		c1.add(password1);
		c1.add(button1);
		c1.add(rb1);
		c1.add(rb2);
		c1.add(rb3);
//		c1.add(button2);
		setVisible(true);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MyFrame3_2 my3 = new MyFrame3_2();
		my3.show();
		my3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

}
